package com.tv.cms.system.menu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tv.cms.system.menu.model.Menu;
import com.tv.cms.system.menu.service.MenuService;
import com.tv.cms.utils.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author
 * @date
 **/
@RestController
@RequestMapping("menu")
public class MenuController {

    @Resource
    private MenuService service;
    @PostMapping("list")
    public Result<List<Menu>> list(){
        List<Menu> parentList = service.list(new QueryWrapper<Menu>().eq("parent_id", 0).eq("status",1));
        for (Menu menu : parentList) {
            List<Menu> list = service.list(new QueryWrapper<Menu>().eq("parent_id", menu.getId()).eq("status", 1));
            for (Menu menu1 : list) {
                menu1.setChildren( service.list(new QueryWrapper<Menu>().eq("parent_id", menu1.getId()).eq("status", 1)));
            }
            menu.setChildren(list);
        }
        return new Result<List<Menu>>().OKDATA(parentList);
    }
}
